module.exports = function(window, document) {
	var apivm = require('../../common/avm.min')(window, document);
	var avm = apivm;
	var api = apivm.api;
	var Component = apivm.Component;
	var $ = apivm.$;
	(function() {
	var Addvideo = /*@__PURE__*/ (function(Component) {
		function Addvideo(props) {
			Component.call(this, props);
			this.data = {
				devicePosition: "back",
				previewUrl: "",
				videoThumbPath: "",
				videoPath: "",
				scanCodeMode: false,
				isRecord: false,
				isPreview: false,
				videoContent: ""
			};
		}

		if (Component) Addvideo.__proto__ = Component;
		Addvideo.prototype = Object.create(Component && Component.prototype);
		Addvideo.prototype.constructor = Addvideo;
		Addvideo.prototype.inputFn = function(e) {
			// console.log(e.detail.value);
			this.data.videoContent = e.detail.value;
		};
		Addvideo.prototype.publishFn = function() {
			var this$1 = this;

			api.ajax(
				{
					url: "https://a6196736472444-dev.apicloud-saas.com/api/employees/upload",
					method: "post",
					data: {
						values: {
							filename: new Date().getTime() + ""
						},

						files: {
							file: this.data.videoPath
						}
					}
				},

				function(ret, err) {
					console.log("ret", ret);
					console.log(err);

					api.ajax(
						{
							url: "https://a6197037785854-dev.apicloud-saas.com/api/videos",
							method: "post",
							data: {
								body: {
									nickname: "老陈",
									content: this$1.data.videoContent,
									like: 0,
									share: 0,
									collect: 0,
									comment: 0,
									playnum: 0,
									pubtime: new Date().getTime() + "",
									src: ret.data.url,
									poster: "https://a415432669.github.io/shortvideo/poster0.jpg",
									headimg: "https://a415432669.github.io/shortvideo/000.jpg"
								}
							}
						},

						function(ret, err) {
							console.log("插入成功", ret);
						}
					);
				}
			);
		};
		Addvideo.prototype.chooseVideo = function(e) {
			var this$1 = this;

			wx.chooseMedia({
				count: 1,
				mediaType: ["video"],
				sourceType: ["ablum"], //, 'camera'
				success: function(res) {
					console.log(res);
					this$1.data.videoPath = res.tempFiles[0].tempFilePath;
					this$1.data.isPreview = true;
				}
			});
		};
		Addvideo.prototype.onstop = function(e) {
			console.log("onstop");
		};
		Addvideo.prototype.onerror = function(e) {
			console.log("onerror");
		};
		Addvideo.prototype.oninitdone = function(e) {
			console.log("oninitdone");
		};
		Addvideo.prototype.onscancode = function(e) {
			var text = e.detail.text;
			api.alert({
				msg: text
			});
		};
		Addvideo.prototype.switchMode = function(e) {
			this.data.scanCodeMode = !this.data.scanCodeMode;
		};
		Addvideo.prototype.takePhoto = function(e) {
			var this$1 = this;

			var obj = document.getElementById("camera");
			if (obj.takePhoto) {
				var that = this;

				obj.takePhoto(
					{
						quality: "high"
					},
					function(ret, err) {
						that.data.previewUrl = ret.tempImagePath;
					}
				);
			} else {
				var ctx = wx.createCameraContext();
				ctx.takePhoto({
					quality: "high",
					success: function(res) {
						this$1.data.previewUrl = res.tempImagePath;
						console.log(res.tempImagePath);
						api.ajax(
							{
								url:
									"https://a6196736472444-dev.apicloud-saas.com/api/employees/upload",
								method: "post",
								data: {
									values: {
										filename: "icon.jpg"
									},

									files: {
										file: res.tempImagePath
									}
								}
							},

							function(ret, err) {
								console.log(ret);
							}
						);
					}
				});
			}
		};
		Addvideo.prototype.startRecord = function(e) {
			var obj = document.getElementById("camera");
			obj.startRecord({
				quality: "high"
			});

			this.data.isRecord = true;
		};
		Addvideo.prototype.stopRecord = function(e) {
			var that = this;
			this.data.isRecord = false;
			this.data.isPreview = true;
			var obj = document.getElementById("camera");
			obj.stopRecord(
				{
					quality: "high"
				},
				function(ret, err) {
					that.data.videoThumbPath = ret.tempThumbPath;
					that.data.videoPath = ret.tempVideoPath;
				}
			);
		};
		Addvideo.prototype.switchDevicePosition = function() {
			this.data.devicePosition =
				this.data.devicePosition == "back" ? "front" : "back";
		};
		Addvideo.prototype.render = function() {
			return apivm.h(
				"scroll-view",
				{class: "main", "scroll-y": true},

				apivm.h(
					"view",
					null,
					apivm.h("camera", {
						id: "camera",
						"device-position": this.data.devicePosition,
						onstop: this.onstop,
						onerror: this.onerror,
						oninitdone: this.oninitdone
					}),

					!this.data.isRecord
						? apivm.h(
								"button",
								{class: "recordBtn", onclick: this.startRecord},
								apivm.h("image", {src: "../../image/record.png"})
						  )
						: apivm.h(
								"button",
								{class: "recordBtn", onclick: this.stopRecord},
								apivm.h("image", {src: "../../image/recording.png"})
						  ),

					apivm.h(
						"button",
						{class: "rotateBtn", onclick: this.switchDevicePosition},
						apivm.h("image", {src: "../../image/rotate.png"})
					),

					apivm.h(
						"button",
						{class: "camera", onclick: this.chooseVideo},
						apivm.h("image", {src: "../../image/camera.png"})
					),

					this.data.isPreview
						? apivm.h(
								"view",
								null,
								apivm.h("textarea", {
									oninput: this.inputFn,
									class: "textarea",
									maxlength: "50",
									autofocus: true,
									placeholder: "请输入视频简介"
								}),
								apivm.h("video", {
									class: "video",
									id: "video",
									src: this.data.videoPath,
									poster: this.data.videoThumbPath
								}),
								apivm.h(
									"button",
									{class: "publishBtn", onClick: this.publishFn},
									"发布"
								)
						  )
						: null
				)
			);
		};

		return Addvideo;
	})(Component);
	apivm.define("addVideo", Addvideo);
	apivm.render(apivm.h("addVideo", null), "body");
})();

	window['createApp'] = function() {
		apivm.$_start();
	}
	return avm;
}